package com.ny.zmb.openapi.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang.ArrayUtils;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.util.List;

/**
 * 进件资料审核状态
 * ============================
 * ZMB状态
 * 0    未提交
 * 3    提交未审核
 * 2    正在审核
 * 1    审核通过
 * -1   审核未通过
 * Ys状态
 * ====================
 * 0    未提交
 * 5    提交未审核
 * 4    正在审核
 * 3    签约中
 * 2    签约成功
 * 1    审核通过
 * -1   审核未通过
 * -2   签约成功失败
 */

@Data
@AllArgsConstructor
@TableName("pm_register_examine")
public class PmRegisterExamine {


    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 外部商户号
     */
    private String outMerchantNo;
    /**
     * 银盛商户号
     */
    private String merchantNo;
    /**
     * 用户ID
     */
    private Integer userId;
    /**
     * zmb状态
     * 0    未提交
     * 3    提交未审核
     * 2    正在审核
     * 1    审核通过
     * -1   审核未通过
     */
    private int status;
    /**
     * 摘墨宝更新时间
     */
    private Date updatedDate;
    /**
     * 备注
     */
    private String msg;
    /**
     * 银盛审核状态
     * 0    未提交
     * 5    提交未审核
     * 4    正在审核
     * 3    签约中
     * 2    签约成功
     * 1    审核通过
     * -1   审核未通过
     * -2   签约成功失败
     * 6    无需提交银盛审核
     */
    private int ysStatus;
    /**
     * 银盛审核更新时间
     */
    private Date ysUpdatedDate;
    /**
     * 银盛返回内容
     */
    private String ysReturnData;

    public PmRegisterExamine() {
        this.status = -1;
        this.ysStatus = -1;
        this.updatedDate = new Date();
        this.ysUpdatedDate = new Date();
    }

    public PmRegisterExamine(String outMerchantNo) {
        this.outMerchantNo = outMerchantNo;
        this.status = -1;
        this.ysStatus = -1;
        this.updatedDate = new Date();
        this.ysUpdatedDate = new Date();
    }

    public PmRegisterExamine(Integer userId, String outMerchantNo) {
        this.outMerchantNo = outMerchantNo;
        this.userId = userId;
        this.updatedDate = new Date();
        this.status = -1;
        this.ysStatus = -1;
        this.ysUpdatedDate = new Date();
    }

    public PmRegisterExamine updateZMB() {
        setStatus(status);
        this.updatedDate = new Date();
        this.msg = null;
        return this;
    }

    public PmRegisterExamine updateZMB(int status, String msg) {
        setStatus(status);
        this.updatedDate = new Date();
        this.msg = msg;
        return this;
    }

    public PmRegisterExamine updateYS(int status, String msg) {
        setYSStatus(status);
        this.ysUpdatedDate = new Date();
        this.ysReturnData = msg;
        return this;
    }

    public PmRegisterExamine updateYS() {
        setYSStatus(status);
        this.ysStatus = 0;
        this.ysUpdatedDate = new Date();
        this.ysReturnData = null;
        return this;
    }

    public String zmbStatusJudge() {
        switch (this.status) {
            case 0:
                return "未提交";
            case 3:
                return "已提交未审核";
            case 2:
                return "正在审核";
            case 1:
                return "审核通过";
            case -1:
                return "审核未通过";
            default:
                return "未知状态";
        }
    }

    public String ysStatusJudge() {
        switch (this.ysStatus) {
            case 0:
                return "未提交";
            case 5:
                return "已提交未审核";
            case 4:
                return "正在审核";
            case 3:
                return "签约中";
            case 2:
                return "签约成功";
            case 1:
                return "审核通过";
            case -1:
                return "审核未通过";
            case -2:
                return "签约成功失败";
            default:
                return "未知状态";
        }
    }

    public void setStatus(int status) {
        Integer[] arrZMB = {-1, 0, 1, 2, 3};
        if (ArrayUtils.contains(arrZMB, status)) {
            this.status = status;
        } else {
            throw new RuntimeException("状态值" + status + " 对象范围错误");
        }
    }

    public void setYSStatus(int status) {
        Integer[] arrYS = {-2, -1, 0, 1, 2, 3, 4, 5, 6};
        if (ArrayUtils.contains(arrYS, status)) {
            this.ysStatus = status;
        } else {
            throw new RuntimeException("YS状态值" + status + "对象范围错误");
        }
    }
}
